package com.dynamicthreadpool.spi.support;

import com.dynamicthreadpool.spi.QueueFactory;
import com.dynamicthreadpool.spi.URL;
import java.util.concurrent.*;

/**
 * ArrayBlockingQueue实现的队列工厂
 */
public class ArrayBlockingQueueFactory implements QueueFactory {

    @Override
    public BlockingQueue<Runnable> createQueue(URL url) {
        int queues = url.getParameter("queues", 0);
        // 如果队列大小为0或负数，则使用默认值
        return new ArrayBlockingQueue<>(queues <= 0 ? 200 : queues);
    }
}